package cn.domain;

import java.util.List;

/**
 * Created by Administrator on 2017/4/11.
 */
public class PageBean {
    /**
     * 从页面提交过来的参数
     */
    private int currentPage;//当前页码

    public List getRecordList() {
        return recordList;
    }

    public void setRecordList(List recordList) {
        this.recordList = recordList;
    }

    private int pageSize;//每页记录数
    /**
     * 查询数据库获得
     */
    private int recordCount;//总记录数
    private List recordList;//页面要显示的数据类型
    /**
     * 有上面4个计算获得
     */
    private int pageCount;//总页码
    private int behinPageIndex;//开始页码
    private int endPageIndex;//末尾页码

    public PageBean(int currentPage, int pageSize, int recordCount, List recordList) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.recordCount = recordCount;
        this.recordList = recordList;
        //如果总记录数为101则只会算出10也数据，而剩余1条不会分页
        //假设recordCount为101      pageSize为10        则为101+9=110     结果为110/10
        this.pageCount=(this.recordCount+this.pageSize-1)/this.pageSize;

        if(this.pageCount<=10){
            this.behinPageIndex=1;
            this.endPageIndex=this.pageCount;
        }else{
            this.behinPageIndex=this.currentPage-4;
            this.endPageIndex=this.currentPage+5;
            if(this.behinPageIndex<1){
                this.behinPageIndex=1;
                this.endPageIndex=10;
            }
            if(this.endPageIndex>this.pageCount){
                this.endPageIndex=this.pageCount;
                this.behinPageIndex=this.endPageIndex-9;
            }
        }
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getRecordCount() {
        return recordCount;
    }

    public void setRecordCount(int recordCount) {
        this.recordCount = recordCount;
    }

    public int getBehinPageIndex() {
        return behinPageIndex;
    }

    public void setBehinPageIndex(int behinPageIndex) {
        this.behinPageIndex = behinPageIndex;
    }

    public int getEndPageIndex() {
        return endPageIndex;
    }

    public void setEndPageIndex(int endPageIndex) {
        this.endPageIndex = endPageIndex;
    }
}
